package com.talent.study.map;

import java.util.regex.Pattern;

/**
 * @ClassName：MapTest
 * @Author: hszhou
 * @Date: 2025/1/21 16:57
 * @Description: 必须描述类做什么事情, 实现什么功能
 */
public class MapTest {
    public static boolean matchPath(String configuredPath, String requestPath) {
        String patternString;
        if (configuredPath.equals("a/**")) {
            patternString = "a(/.*)?";
        } else if (configuredPath.equals("a/*")) {
            patternString = "a/[^/]*";
        } else {
            // 可根据需要添加更多的配置路径处理逻辑
            patternString = configuredPath;
        }
        Pattern pattern = Pattern.compile(patternString);
        return pattern.matcher(requestPath).matches();
    }

    public static void main(String[] args) {
        String configuredPath1 = "a/**";
        String configuredPath2 = "a/*";
        String requestPath = "a/1/2/12";
        // 测试配置 a/** 是否匹配请求路径 a/1/2
        boolean result1 = matchPath(configuredPath1, requestPath);
        // 测试配置 a/* 是否匹配请求路径 a/1/2
        boolean result2 = matchPath(configuredPath2, requestPath);
        System.out.println("Configured path a/** matches request path a/1/2: " + result1);
        System.out.println("Configured path a/* matches request path a/1/2: " + result2);
    }
}
